export default {
    namespaced: true,
    state: {
        cartList: uni.getStorageSync('cartList') || []

    },
    getters: {

    },
    mutations: {
        cartAdd(state, playload) {
            const index = state.cartList.findIndex(item => item.goods_id === playload.value.goods_id)
            if (index === -1) {
                state.cartList.push({...playload.value, nums: 1, checked: true })

            } else {
                state.cartList[index].nums++
            }
            uni.setStorageSync('cartList', state.cartList)
        },
        changeCartCheck(state, playload) {
            state.cartList[playload.index].checked = !state.cartList[playload.index].checked
            uni.setStorageSync('cartList', state.cartList)
        },
        cartGoodsNumUpdata(state, playload) {
            state.cartList[playload.index].nums += playload.unit
            uni.setStorageSync('cartList', state.cartList)
        },
        cartGoodsRemove(state, playload) {
            state.cartList.splice(playload.index, 1)
            uni.setStorageSync('cartList', state.cartList)

        },
        cartGoosAllcheck(state, playload) {
            state.cartList.forEach(item => item.checked = playload.checked)
            uni.setStorageSync('cartList', state.cartList)

        }
    },
    actions: {

    }
}